package edu.ntu.cloudroid.model.policy;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import edu.ntu.cloudroid.model.IDs;
import edu.ntu.cloudroid.model.UserData;
import edu.ntu.cloudroid.xacml.builder.policy.AbstractPolicyBuilder;
import edu.ntu.cloudroid.xacml.builder.policy.SimpleSlidingWindowBuilder;
import edu.ntu.cloudroid.xacml.builder.policy.SimpleStatBuilder;
import edu.ntu.cloudroid.xacml.obligation.ObligationHandle;
import edu.ntu.cloudroid.xacml.obligation.SlidingWindowObligation;
import edu.ntu.cloudroid.xacml.obligation.StatsObligation;

//This policy will only contains the data column index, 
//over which the stats is derived
@PersistenceCapable(detachable="true")
@Inheritance
public class SimpleStats extends AbstractPrivacyPreference{			
	
	@Persistent
	private int statFunctionId;
	
	@Persistent
	private boolean inputRequired;//if user input is to be included in the request
	
	@Override
	public void initializePreference(String[] values) throws Exception{
		// functionId dataColumnIdx
		this.statFunctionId = new Integer(values[0]).intValue();
		this.setDataColumnIndex(new Integer(values[1]).intValue());
		this.inputRequired = new Boolean(values[2]).booleanValue();
	}
	
	public boolean isInputRequired(){
		return this.inputRequired;
	}
	
	public int getStatFunctionId(){
		return this.statFunctionId;
	}
	
	@Override
	public AbstractPolicyBuilder getPolicyBuilder() {
		return new SimpleStatBuilder();
	}

	@Override
	public UserData getMetaData(Object param) throws Exception {
		String type = "";
		if (param == null)
			type = type + AbstractPrivacyPreference.ISALL;
		else
			type = type + AbstractPrivacyPreference.ISGROUP + ","
					+ param.toString();

		String s = this.getUserName() + ","
				+ IDs.PolicyID.SimpleStats.ordinal() + "," + type + ","
				+ this.statFunctionId + "," + this.getDataColumnIndex()
				+ "," + this.isInputRequired();

		return new PolicyInfo(this.getUserName(), s.split(","));

	}
				
}
